package com.iphanta.community.activity.voting.web;

import com.iphanta.community.activity.photographic.common.BallBox;
import com.iphanta.community.activity.photographic.common.BallBoxSelector;
import com.iphanta.community.activity.photographic.service.PhotographicService;
import com.iphanta.community.activity.voting.entity.Vote;
import com.iphanta.community.activity.voting.service.VoteService;
import com.iphanta.community.common.entity.DataResult;
import com.iphanta.community.common.message.CommunityMessage;
import com.iphanta.community.common.message.MessageContent;
import com.iphanta.community.common.utils.JsonUtils;
import com.iphanta.community.common.utils.ResultUtils;
import com.iphanta.community.remote.service.TimService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.*;

/**
 * @author 墨声 E-mail: zehong.hongframe.huang@gmail.com
 * create time: 4/8/22 3:21 PM
 */
@RestController
@RequestMapping("community/vote/")
public class VoteController {

    @Autowired
    private VoteService voteService;

    @Autowired
    private PhotographicService photographicService;

    @Autowired
    private TimService timService;

    @PostMapping("vote")
    public DataResult vote(@RequestBody Vote vote) {
//        voteService.vote(vote);

//        List<BallBox> ballBoxes = new ArrayList<>();
//        Random random = new Random(System.currentTimeMillis());
//        Map<Integer, List<Long>> im = new HashMap<>();
//        for (int i = 0; i < 100; i++) {
//            int w = random.nextInt(10) + 1;
//            BallBox box = new BallBox(100000L + i, w);
//
//            List<Long> l = im.get(w);
//            if(l == null) {
//                l = new ArrayList<>();
//                im.put(w, l);
//            }
//            l.add(box.getDynamicId());
//            ballBoxes.add(box);
//        }
//        for(Map.Entry<Integer, List<Long>> entry : im.entrySet()) {
//            System.out.println("Key = " + entry.getKey() + ", ids = " + entry.getValue());
//        }
//
//        for (int i = 0; i < 20; i++) {
//            BallBoxSelector selector = new BallBoxSelector(new ArrayList<>(ballBoxes), random);
//            System.out.println(JsonUtils.INSTANCE.toJsonString(selector.choice(10)));
//        }
//        photographicService.take(">>>>>>");
        CommunityMessage message = new CommunityMessage();
        message.setType(2);
        message.setMessageSeq(1000L);
        MessageContent content = new MessageContent();
        content.setText("Hi guy");
        content.setTitle("What's up.");
        content.setUrl("https://i0.hdslb.com/bfs/face/10abbc362f33394b32662c32c461471cb71fcb6c.jpg");
        message.setContent(content);

        this.timService.sendMessage("hand-pick-1001", "0012345", message);
        return ResultUtils.SUCCESS.result();
    }

}
